#******************************************************************
#
# Copyright 2015 Samsung Electronics All Rights Reserved.
#
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

##
# ResourceBroker Unit Test build script
##

Import('env')

if env.get('RELEASE'):
	env.AppendUnique(CCFLAGS = ['-Os'])
	env.AppendUnique(CPPDEFINES = ['NDEBUG'])
else:
	env.AppendUnique(CCFLAGS = ['-g'])

if env.get('LOGGING'):
	env.AppendUnique(CPPDEFINES = ['TB_LOG'])

lib_env = env.Clone()
SConscript(env.get('SRC_DIR') + '/service/third_party_libs.scons', 'lib_env')

######################################################################
#unit test setting
######################################################################
src_dir = lib_env.get('SRC_DIR')
gtest_dir = src_dir + '/extlibs/gtest/gtest-1.7.0'

broker_test_env = lib_env.Clone()
target_os = env.get('TARGET_OS')

######################################################################
# Build flags
######################################################################
gtest = File(gtest_dir + '/lib/.libs/libgtest.a')
gtest_main = File(gtest_dir + '/lib/.libs/libgtest_main.a')

broker_test_env.AppendUnique(CPPPATH = ['../include'])
broker_test_env.AppendUnique(CPPPATH = ['../../../include'])
broker_test_env.AppendUnique(CPPPATH = ['../../common/primitiveResource/include'])
broker_test_env.AppendUnique(CPPPATH = ['../../common/expiryTimer/include'])
broker_test_env.AppendUnique(CPPPATH = ['../../common/expiryTimer/src'])
broker_test_env.AppendUnique(CPPPATH = ['../../common/utils/include'])

broker_test_env.PrependUnique(CPPPATH = [env.get('SRC_DIR')+'/extlibs/hippomocks-master',
                             gtest_dir + '/include'])
broker_test_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
broker_test_env.PrependUnique(LIBS = ['rcs_client','rcs_common', 'oc', 'octbstack', 'oc_logger', 'connectivity_abstraction', 'coap', gtest, gtest_main])

if target_os not in ['windows', 'winrt']:
    broker_test_env.AppendUnique(CXXFLAGS = ['-O2', '-g', '-Wall', '-fmessage-length=0', '-std=c++0x'])

if target_os == 'linux':
    broker_test_env.AppendUnique(LIBS = ['pthread'])

######################################################################
# Build Test
######################################################################

broker_test_src = env.Glob('./*.cpp')
broker_test = broker_test_env.Program('broker_test', broker_test_src)
Alias("broker_test", broker_test)
env.AppendTarget('broker_test')

if env.get('TEST') == '1':
        target_os = env.get('TARGET_OS')
        if target_os == 'linux':
                from tools.scons.RunTest import *
                run_test(broker_test_env,
                         '',
                         'service/resource-encapsulation/src/resourceBroker/unittest/broker_test')
